<template>
  <el-dialog
    :visible.sync="visible"
    class="dialogStyle"
    :show="show"
    :title="'规则确认——'+title"
    width="60%"
    @close="OnClose()"
  >
    <el-table
      :data="tableData"
      :header-cell-style="{'text-align':'center'}"
      :cell-style="{'text-align':'center',padding:'0px'}"
      stripe
      style="width: 100%"
      border
      height="400px"
    >
      <el-table-column prop="drugId" label="肾损害" width="100"></el-table-column>
      <el-table-column prop="drugName" label="操作" width="100" fixed="left">
        <template slot-scope="scope">
          <el-button type="text" @click="Confirm(scope.row.id,3)">确认</el-button>
          <el-button type="text" @click="Confirm(scope.row.id,1)">作废</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="remark" label="状态"></el-table-column> -->
      <!-- <el-table-column prop="drugName" label="药品名称" width="100"></el-table-column> -->
      <el-table-column prop="stRouteId" label="给药途径"></el-table-column>
      <el-table-column prop="renLabel" label="肾损等级" width="115">
        <!-- 给药类型 1  全身给药     2  局部给药  3  所有方式给药   0  系统默认 -->
        <template
          slot-scope="scope"
        >{{(scope.row.renLabel==0)?"无肾损害":(scope.row.renLabel==1)?"肾功能不全":(scope.row.renLabel==2)?"轻度肾损害":(scope.row.renLabel==3)?"中度肾损害":(scope.row.renLabel==4)?"重度肾损害":""}}</template>
      </el-table-column>
      <!-- <el-table-column prop="ids" label="drugId_routeId_hepLabel"></el-table-column> -->
      <el-table-column prop="ageWeighLabel" label="年龄高值标签"></el-table-column>
      <el-table-column prop="ageLow" label="年龄低值"></el-table-column>
      <el-table-column prop="unequalLow" label="是否不等于年龄低值" width="150">
        <template
          slot-scope="scope"
        >{{(scope.row.unequalLow==0)?"等于":(scope.row.unequalLow==1)?"不等于":""}}</template>
      </el-table-column>
      <el-table-column prop="ageLowUnit" label="年龄低值单位" width="105"></el-table-column>
      <el-table-column prop="ageHigh" label="年龄高值"></el-table-column>
      <el-table-column prop="unequalHigh" label="是否不等于年龄低值" width="150">
        <template
          slot-scope="scope"
        >{{(scope.row.unequalHigh==0)?"等于":(scope.row.unequalHigh==1)?"不等于":""}}</template>
      </el-table-column>
      <el-table-column prop="ageHighUnit" label="年龄高值单位" width="105"></el-table-column>
      <el-table-column prop="weighLow" label="大于等于（KG）" width="105"></el-table-column>
      <el-table-column prop="weighHigh" label="小于等于（KG）" width="105"></el-table-column>
      <el-table-column prop="calculateLabel" label="计算方式" width="105"></el-table-column>
      <el-table-column prop="doseEachLow" label="每次低剂量" width="105"></el-table-column>
      <el-table-column prop="doseEachLowUnit" label="每次低剂量单位" width="105"></el-table-column>
      <el-table-column prop="doseEachHigh" label="每次高剂量" width="105"></el-table-column>
      <el-table-column prop="doseEachHighUnit" label="每次高剂量单位" width="105"></el-table-column>
      <el-table-column prop="doseDayLow" label="日剂量低值" width="105"></el-table-column>
      <el-table-column prop="doseDayLowUnit" label="日剂量低值单位" width="105"></el-table-column>
      <el-table-column prop="doseDayHigh" label="日剂量高值" width="105"></el-table-column>
      <el-table-column prop="doseDayHighUnit" label="日剂量高值单位" width="105"></el-table-column>

      <el-table-column prop="freQuencyLow" label="低频次" width="105"></el-table-column>
      <el-table-column prop="freQuencyLowDay" label="日低频次" width="105"></el-table-column>
      <el-table-column prop="freQuencyHigh" label="高频次" width="105"></el-table-column>
      <el-table-column prop="freQuencyHighDay" label="日高频次" width="105"></el-table-column>

      <!-- <el-table-column prop="slCode" label="警示级别">
      <template slot-scope="scope">-->
      <!-- 0:拦截，1：禁忌，2：不推荐，3：轻微 -->
      <!-- {{(scope.row.slCode==0)?"拦截":(scope.row.slCode==1)?"禁忌":(scope.row.slCode==2)?"不推荐":(scope.row.slCode==3)?"轻微":""}}
        </template>
      </el-table-column>-->
      <el-table-column prop="remark" label="备注"></el-table-column>
      <el-table-column prop="abstractDesc" label="警示信息"></el-table-column>
      <el-table-column prop="insert_TIME" label="新增时间" width="160">
        <template slot-scope="scope">{{getdate(scope.row.insert_TIME/1000)}}</template>
      </el-table-column>
      <el-table-column prop="update_TIME" label="更新时间" width="160">
        <template slot-scope="scope">{{getdate(scope.row.update_TIME)}}</template>
      </el-table-column>
      <el-table-column prop="insert_NAME" label="新增人名称" width="95"></el-table-column>
      <el-table-column prop="confirm_NAME" label="确认人名称" width="95"></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="this.pageSize"
        layout="total, prev, pager, next"
        :total="this.total"
      ></el-pagination>
    </div>
    <span slot="footer" class="dialog-footer" style="padding-bottom: 10px;">
      <el-button size="medium" type="primary" @click="Reset()">重 置</el-button>
      <el-button size="medium" @click="OnClose">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
// import { title, DrugId } from "../../../../settings";
import { getdosageDrugId, getdate, updateRendosageState } from "@/api/rad";
export default {
  name: "TemplateDialog",
  props: {
    show: { type: Boolean, default: false },
    title: "",
    drugid: "",
    drugCode: "",
  },
  data() {
    return {
      visible: this.show,
      // adultDrugId: "",
      page: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
    };
  },
  watch: {
    show: {
      immediate: true,
      handler(show) {
        this.visible = this.show;
      },
    },
  },
  // created: function () {
  //   this.adultDrugId = title;
  //   this.getAdultDrugConf();
  // },
  methods: {
    handleSizeChange(newSize) {
      this.pageSize = newSize;
      this.getList(this.drugid);
    },
    handleCurrentChange(newPage) {
      this.page = newPage;
      this.getList(this.drugid);
    },
    OnClose() {
      this.$emit("update:show", false);
    },
    getdate(date) {
      return this.$rad.getdate(date);
    },
    async getList(drugid) {
      let res = await this.$rad.getdosageDrugId({
        rendosageDrugId: drugid,
        page: this.page,
        pageSize: this.pageSize,
      });
      this.total = res.total;
      this.tableData = res.rows;
      console.log(res);
      // console.log(this.drugid);
    },
    Confirm(id, state) {
      if (state == 3) {
        this.$confirm("此操作将确认该规则, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.ConfirmRule(id, state);
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      } else if ((state = 1)) {
        this.$confirm("此操作将作废该规则, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.ConfirmRule(id, state);
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
    },
    async Reset() {
      console.log(this.drugCode);
      let res = await this.$rad.ResetemptyRendosageDrugId({
        drugCode: this.drugCode,
      });
      console.log(res);
      if (res.code == 1) {
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
    async ConfirmRule(id, state) {
      let res = await this.$rad.updateRendosageState({
        id: id,
        state: state,
      });
      console.log(res);
      if (res.code == 1) {
        this.getList(this.drugid);
        return this.$message({
          type: "success",
          message: (state == 1 ? "作废" : "确认") + res.msg,
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
  },
};
</script>
<style scoped>
.dialogStyle >>> .el-dialog__footer {
  padding-bottom: 10px;
}
</style>